from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileRequired, FileAllowed
from wtforms import StringField, TextAreaField, FloatField, SubmitField, DateField, BooleanField, SelectField
from wtforms.validators import DataRequired, Length, NumberRange
from datetime import datetime

class ThesisForm(FlaskForm):
    title = StringField('论文题目', validators=[
        DataRequired(message='题目不能为空'),
        Length(max=200, message='题目长度不能超过200个字符')
    ])
    description = TextAreaField('论文描述')
    programming_language = SelectField('编程语言', 
        choices=[
            ('', '请选择编程语言'),
            ('Python', 'Python'),
            ('Java', 'Java'),
            ('C++', 'C++'),
            ('C#', 'C#'),
            ('JavaScript', 'JavaScript'),
            ('PHP', 'PHP'),
            ('Go', 'Go'),
            ('MATLAB', 'MATLAB'),
            ('R', 'R'),
            ('其他', '其他')
        ],
        validators=[DataRequired(message='请选择编程语言')]
    )
    price = FloatField('额外预算（如有）', validators=[
        NumberRange(min=0, max=1000, message='额外预算必须在0-1000元之间')
    ])
    
    contact_info = StringField('联系方式（QQ：1234567890/ 微信：1234567890/ 邮箱：1234567890@qq.com）', validators=[
        DataRequired(message='联系方式不能为空'),
        Length(max=100, message='联系方式长度不能超过100个字符')
    ])
    deadline = DateField('期望完成日期', 
        validators=[DataRequired(message='请选择期望完成日期')],
        default=datetime.today  # 设置默认值为今天
    )
    need_environment = BooleanField('是否需要环境配置（+100元）')
    
    proposal_file = FileField('开题报告（选填）', validators=[
        FileAllowed(['pdf', 'doc', 'docx'], message='只允许上传 PDF 或 Word 文档')
    ])
    
    thesis_type = SelectField('毕业设计类型', 
        choices=[
            ('', '请选择毕业设计类型（必选）'),
            ('design', '毕业设计（700元）'),
            ('thesis', '毕业论文（500元）'),
            ('full', '全套服务（1000元）')
        ],
        validators=[DataRequired(message='请选择毕业设计类型')]
    )
    
    submit = SubmitField('提交')

    def __init__(self, *args, is_edit=False, **kwargs):
        super(ThesisForm, self).__init__(*args, **kwargs) 